import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
/* Layout */
import Layout from '@/layout'
import homeLayout from '@/layout/home'
import clientLayout from '@/layout/client'

export let constantRoutes = [
  {
    path: '/',
    component: () => import('@/views/redirect/index'),
    hidden: true,
  },
  {
    path: '/login',
    component: () => import('@/views/clientLogin/index'),
    hidden: true
  },
  {
    path: '/systemLogin',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',  //关闭窗口
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/home',
    component: homeLayout,
    redirect: '/home',
    hidden: true,
    children: [
      {
        path: '/home',
        component: () => import('@/views/home/index'),
        name: 'home',
        meta: { title: '控制台', icon: 'dashboard', affix: true, noCache: false  }
      }
    ]
  },
  {
    path: '/client',
    component: clientLayout,
    redirect: '/client',
    hidden: true,
    children: [
      {
        path: '/client',
        component: () => import('@/views/home/index'),
        name: 'client',
        meta: { title: '客户端', icon: 'dashboard', affix: true, noCache: false  }
      }
    ]
  },
  {
    path: '/clientManage',
    component: clientLayout,
    meta: { title: '课件管理', icon: 'el-icon-folder-opened', noCache: false },
    type:9,
    children: [
      {
        path: 'courseware',
        component: () => import('@/views/clientManage/courseware'),
        name: 'courseware',
        meta: { title: ' 课件列表', icon: 'el-icon-folder-opened', noCache: false }
      }
    ]
  }, 
  {
    path: '/clientManage',
    component: clientLayout,
    meta: { title: '课件管理', icon: 'el-icon-s-opportunity', noCache: false },
    type:9,
    children: [
      {
        path: 'feedback',
        component: () => import('@/views/clientManage/feedback'),
        name: 'feedback',
        meta: { title: ' 意见反馈', icon: 'el-icon-edit-outline', noCache: false }
      }
    ]
  },

  {
    path: '/teachManage',
    component: Layout,
    meta: { title: '课件管理',icon: 'el-icon-folder-opened', noCache: false, keepAlive: true },
    type:1,
    children: [
      {
        path: 'index',
        component: () => import('@/views/teachManage/index'),
        name: 'teachList',
        meta: { title: ' 课件列表', icon: 'el-icon-reading', noCache: false }
      },
      {
        path: 'course',
        component: () => import('@/views/courseManage/index'),
        name: 'course',
        meta: { title: ' 课程分类', icon: 'el-icon-notebook-2', noCache: false,keepAlive: false }
      },
    ]
  },
  {
    path: '/userManage',
    component: Layout,
    meta: { title: '用户管理', icon: 'chart', noCache: false, keepAlive: true },
    type:1,
    children: [
      {
        path: 'index',
        component: () => import('@/views/userManage/index'),
        name: 'userManage',
        meta: { title: ' 用户列表', icon: 'el-icon-s-custom', noCache: false }
      }
    ]
  },
  {
    path: '/analysisManage',
    component: Layout,
    meta: { title: '统计报表', icon: 'chart', noCache: false, keepAlive: true},
    type:1,
    children: [
      {
        path: 'index',
        component: () => import('@/views/analysisManage/index'),
        name: 'analysisList',
        meta: { title: ' 课件统计', icon: 'el-icon-pie-chart', noCache: false, keepAlive: true  }
      }
    ]
  },
  {
    path: '/feedbackManage',
    component: Layout,
    meta: { title: '意见与建议管理', icon: 'chart', noCache: false },
    type:1,
    children: [
      {
        path: 'index',
        component: () => import('@/views/feedbackManage/index'),
        name: 'feedbackList',
        meta: { title: ' 意见反馈', icon: 'el-icon-position', noCache: false }
      }
    ]
  },
  {
    path: '/systemManage',
    component: Layout,
    meta: { title: '系统设置', icon: 'el-icon-setting', noCache: false },
    type:1,
    children: [
      {
        path: 'user',
        component: () => import('@/views/systemManage/user'),
        name: 'systemUser',
        meta: { title: ' 账户列表', icon: 'el-icon-user', noCache: false }
      },
      {
        path: 'role',
        component: () => import('@/views/systemManage/role'),
        name: 'role',
        meta: { title: ' 角色列表', icon: 'el-icon-s-check', noCache: false }
      },
      {
        path: 'school',
        component: () => import('@/views/systemManage/school'),
        name: 'school',
        meta: { title: ' 学校管理', icon: 'el-icon-school', noCache: false }
      },
      {
        path: 'position',
        component: () => import('@/views/systemManage/position'),
        name: 'position',
        meta: { title: ' 职务管理', icon: 'el-icon-postcard', noCache: false }
      }
    ]
  },
  {
    path: '/dataManage',
    component: Layout,
    meta: { title: '用户中心', icon: 'el-icon-s-grid', noCache: false },
    type:6,
    children: [
      {
        path: 'account',
        component: () => import('@/views/dataManage/account'),
        name: 'account',
        meta: { title: '账户列表', icon: 'el-icon-user',keepAlive: true, noCache: false }
      },
      {
        path: 'userList',
        component: () => import('@/views/dataManage/userList'),
        name: 'userList',
        meta: { title: '用户列表', icon: 'el-icon-s-check',keepAlive: true, noCache: false }
      }
    ]
  },
  // {
  //   path: '/icon',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/icons/index'),
  //       name: 'Icons',
  //       meta: { title: 'Icons', icon: 'icon', noCache: false }
  //     }
  //   ]
  // },
]

export const asyncRoutes = [  ];
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
// 防止连续点击多次路由报错
// let routerPush = Router.prototype.push;
// Router.prototype.push = function push(location) {
//   return routerPush.call(this, location).catch(err => err)
// }

const router = createRouter()
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
export default router
